package com.happy.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.happy.entity.SubjectEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: Wuzh
 * @Description:
 * @Date Created in 17:10 2021/1/31
 * @return
 */
@Mapper
public interface SubjectMapper extends BaseMapper<SubjectEntity> {


    @Select (value = "<script>select si.subjectId,si.subjectContent,si.paperId,pi.paperName AS paperName,si.categoryId, ci.categoryName AS categoryName,si.optionId,oi.optionContent AS optionContent,si.createTime,si.changeTime,si.isUsed from subject_info si left join category_info ci on ci.id = si.categoryId left join paper_info pi on si.paperId = pi.paperId left join option_info oi on si.optionId = oi.optionId <where><if test='subjectEntity.paperId != null'>and si.paperId=#{subjectEntity.paperId}</if></where> order by si.createTime desc limit #{start}, #{size} </script>")
    List<SubjectEntity> queryList ( @Param ("subjectEntity") SubjectEntity subjectEntity, @Param ("start") int start, @Param ("size") int size );

    @Select (value = "<script>select count(1) from subject_info si left join category_info ci on ci.id = si.categoryId left join paper_info pi on si.paperId = pi.paperId left join option_info oi on si.optionId = oi.optionId <where><if test='subjectEntity.paperId != null'>and si.paperId=#{subjectEntity.paperId}</if></where> </script>")
    int totalCount ( @Param ("subjectEntity") SubjectEntity subjectEntity );

}
